import numpy as np
from mpl_toolkits import mplot3d
import matplotlib.pyplot as plt
import pandas as pd
from python_ai.common.xcommon import sep
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import PolynomialFeatures, StandardScaler

np.random.seed(666)
m = 11
x = np.linspace(-3, 3, m)
X = x.reshape(-1, 1)
y = 2 * x ** 2 + 6 * x - 3 + np.random.randn(m) * 5

plt.scatter(x, y)

poly_reg = Pipeline([
    ['poly', PolynomialFeatures(degree=2)],
    ['std', StandardScaler()],
    ['reg', LinearRegression()],
])
poly_reg.fit(X, y)
h = poly_reg.predict(X)

plt.plot(x, h, 'r--')

plt.show()
